package com.per.mybootall.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.json.JSONException;
import org.springframework.stereotype.Component;

import java.util.Random;
@Component
public class GetPhoto {
    public  int note(String number) throws JSONException {//number电话号码，传输进来
        DefaultProfile profile = DefaultProfile.getProfile("请参见支付宝短信验证码文档", "您的ak值", "您的ak值");
        //AK值

        IAcsClient client = new DefaultAcsClient(profile);
        //  String number="19983479861";//电话号码18782235441

        int code = new Random().nextInt(9999);//随机6位验证码

        CommonRequest request = new CommonRequest();
        //request.setProtocol(ProtocolType.HTTPS);
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");

        request.putQueryParameter("RegionId", "cn-hangzhou");
        // request.putQueryParameter("PhoneNumbers", String.valueOf(number));如果号码不是string则使用这个语句
        request.putQueryParameter("PhoneNumbers", number);//number是用户的电话号码（String类型）
        // String jsonStr = JSONObject.numberToString(str);

        request.putQueryParameter("SignName", "微天下");//短信签名
        request.putQueryParameter("TemplateCode", "SMS_164195073");//短信模板
        request.putQueryParameter("TemplateParam","{\"code\":\""+code+"\"}");

        try {
            CommonResponse response = client.getCommonResponse(request);

            System.out.println(response.getData());
        } catch (ClientException e) {
            e.printStackTrace();
        }
        System.out.println(code);

        return code;//随机数验证码





    }
}
